const app = getApp()
Page({
  data: {
    video: 'https://hejianwei.snslearn.com/tmeta/2ce65f1282a718affc6b970e75494886.m3u8?s=be63980839112560c80dd1123c8d4aed&c=895871&id=103798&type=213',
    resource_id: null,
    type: null,
    task_id: null,
    structure_id: null,
    kmapping_id: null,
    resource_info: {},
    next: {},
    previous: {}
  },
  onReady(res) {},
  onLoad(options) {
    var type = options.target_type;
    var resourceId = options.target_id;
    var taskId = options.task_id;
    var kmappingId = options.kmapping_id;
    var structureId = options.structure_id;
    var that = this;
    that.setData({
      resource_id: resourceId,
      type: type,
      task_id: taskId,
      structure_id: structureId,
      kmapping_id: kmappingId
    })
    that.getRsourceDetailInfo();
  },
  getRsourceDetailInfo() {
    var that = this;
    wx.request({
      url: app.globalData.URL + '/kmapping/WebAppAjax/getRsourceDetailInfo&token=' + wx.getStorageSync('token'),
      dataType: 'json',
      method: 'GET',
      data: {
        resource_id: that.data.resource_id,
        type: that.data.type,
        task_id: that.data.task_id,
        structure_id: that.data.structure_id,
        kmapping_id: that.data.kmapping_id
      },
      success: function(res) {
        var _res = res.data;
        if (_res.error_code == 0) {
          var _video = _res.data.resource_info.weike_info.format_resources[0].url;
          that.setData({
            "video": _video,
            'next': _res.data.next,
            'previous': _res.data.previous,
            'resource_info': _res.data.resource_info,
          })
        }
      }
    })
  },
  getaddTaskLog(type) {
    var that = this;
    wx.request({
      url: app.globalData.URL + '/kmapping/WebAppAjax/addTaskLog&token=' + wx.getStorageSync('token'),
      dataType: 'json',
      method: 'GET',
      data: {
        resource_id: that.data.resource_id,
        type: type,
        task_id: that.data.task_id,
        structure_id: that.data.structure_id,
        kmapping_id: that.data.kmapping_id
      },
      success: function(res) {
        var _res = res.data;
        if (_res.error_code == 0) {
          that.setData({})
        }
      }
    })
  },
  /** 
  监听小程序播放开始时传递数据
  **/
  playHandle(e) {
    var that = this;
    that.getaddTaskLog(2);
  },
  /** 
   监听小程序播放结束时传递数据
   **/
  endedHandle(e) {
    var that = this;
    that.getaddTaskLog(3);
  },
  /**
   * 监听H5向小程序传递的数据
   */
  getMessage(e) {

  },
  nextTaskHandle: function(e) {
    var that = this,
      next_url = that.data.next.weixinapp_url;
    wx.redirectTo({
      url: next_url,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})